//
//  CellOfPicText.m
//  ProjectA_ManualGuest
//
//  Created by dingcong on 16/6/22.
//  Copyright © 2016年 丁聪. All rights reserved.
//

#import "CellOfPicText.h"
#import "Masonry.h"
#import "UIImageView+WebCache.h"
#import "ImageTextModle.h"
@implementation CellOfPicText

- (void)dealloc{
    [_viewOfFirstBackground release];
    [_imageOfFirst release];
    [_lableOfFirst release];
    [_lableofFirstUser release];
    [_lableOfFirstCollect release];
    [_model release];
    [super dealloc];
    
    
}

- (instancetype)initWithFrame:(CGRect)frame{
    
    if (self = [super initWithFrame:frame])
    {
        [self creat];
    }
    
    return self;
    
}

- (void)creat{
    
    
//    self.contentView.backgroundColor = [UIColor greenColor];
    
    self.viewOfFirstBackground = [[UIView alloc]init];
    
    self.viewOfFirstBackground.backgroundColor = [UIColor colorWithRed:arc4random() % (256) / 255.0f green:arc4random() % (256) / 255.0f blue:arc4random() % (256) / 255.0f alpha:0.3];
    self.viewOfFirstBackground.layer.cornerRadius = 2;
    [self.contentView addSubview:self.viewOfFirstBackground];
    
    [self.viewOfFirstBackground mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.contentView.mas_top).offset(0);
        make.leading.equalTo(self.contentView.mas_leading).offset(0);
        make.width.equalTo(self.contentView.mas_width);
        make.height.equalTo(self.contentView.mas_height);
    }];
    [self.viewOfFirstBackground release];
    
    
    self.imageOfFirst = [[UIImageView alloc]init];
//    self.imageOfFirst.backgroundColor = [UIColor greenColor];
    [self.viewOfFirstBackground addSubview:self.imageOfFirst];
    [self.imageOfFirst mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.viewOfFirstBackground.mas_top).offset(0);
        make.leading.equalTo(self.viewOfFirstBackground.mas_leading).offset(0);
        make.height.equalTo(self.viewOfFirstBackground).multipliedBy(1.0 / 1.5);
        make.width.equalTo(self.viewOfFirstBackground.mas_width);
        
    }];
    self.imageOfFirst.layer.cornerRadius = 2;
    self.imageOfFirst.layer.masksToBounds = YES;
    [self.imageOfFirst release];
    
    self.lableOfFirst = [[UILabel alloc]init];
//    self.lableOfFirst.backgroundColor = [UIColor yellowColor];
    [self.viewOfFirstBackground addSubview:self.lableOfFirst];
    [self.lableOfFirst mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.imageOfFirst.mas_bottom).offset(5);
        make.leading.equalTo(self.viewOfFirstBackground.mas_leading).offset(12);
        make.width.equalTo(self.contentView).multipliedBy(1.0 / 1.1);
        make.height.offset(20);
    }];
    self.lableOfFirst.font = [UIFont systemFontOfSize:11];
    self.lableOfFirst.text = @"神腿老朱";
    self.lableOfFirst.textColor = [UIColor whiteColor];
    [self.lableOfFirst release];
    
    self.lableofFirstUser = [[UILabel alloc]init];
//    self.lableofFirstUser.backgroundColor = [UIColor redColor];
    [self.viewOfFirstBackground addSubview:self.lableofFirstUser];
    [self.lableofFirstUser mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.lableOfFirst.mas_bottom).offset(0);
        make.leading.equalTo(self.viewOfFirstBackground.mas_leading).offset(12);
        make.width.equalTo(self.lableOfFirst.mas_width);
        make.height.equalTo(self.lableOfFirst.mas_height);
    }];
    self.lableofFirstUser.font = [UIFont systemFontOfSize:10];
    self.lableofFirstUser.textColor = [UIColor grayColor];
    self.lableofFirstUser.text = @"asdfjkjakldsfjkljakldsfjkladfs";
    [self.lableofFirstUser release];
    
    
    UIView *lineOfFirst = [[UIView alloc]init];
    lineOfFirst.backgroundColor = [UIColor lightGrayColor];
    [self.viewOfFirstBackground addSubview:lineOfFirst];
    [lineOfFirst mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.lableofFirstUser.mas_bottom).offset(3);
        make.leading.equalTo(self.viewOfFirstBackground.mas_leading).offset(12);
        make.height.offset(0.5);
        make.width.equalTo(self.lableofFirstUser.mas_width).offset(- 6);
    }];
    [lineOfFirst release];
    
    self.lableOfFirstCollect = [[UILabel alloc]init];
//    self.lableOfFirstCollect.backgroundColor = [UIColor purpleColor];
    [self.viewOfFirstBackground addSubview:self.lableOfFirstCollect];
    
    [self.lableOfFirstCollect mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(lineOfFirst.mas_bottom).offset(3);
        make.leading.equalTo(self.viewOfFirstBackground.mas_leading).offset(12);
        make.height.equalTo(self.lableofFirstUser.mas_height);
        make.width.equalTo(self.lableofFirstUser.mas_width);
        
    }];
    self.lableOfFirstCollect.textColor = [UIColor grayColor];
    self.lableOfFirstCollect.font = [UIFont systemFontOfSize:8];
    self.lableOfFirstCollect.text = @"jijisasdad";
    [self.lableOfFirstCollect release];
    
    
    
    
    
}

- (void)setModel:(ImageTextModle *)model{
    
    [self.imageOfFirst sd_setImageWithURL:[NSURL URLWithString:model.host_pic] placeholderImage:nil];
    self.imageOfFirst.layer.cornerRadius = 4;
    self.lableOfFirst.text = model.subject;
    if (model.user_name)
    {
        
        NSString *str = @"by  ";
        self.lableofFirstUser.text = [str stringByAppendingString:model.user_name];
    }
    else
    {
        self.lableofFirstUser.text = @"by (null)";
    }
    self.lableOfFirstCollect.text = [NSString stringWithFormat:@"%@人气 / %@收藏",model.view, model.collect];
    
}


@end
